package com.common.app.widget.mybanner;

import static com.common.base.config.AppConfig.GLIDE_FADE_IN_TIME;
import android.content.Context;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;
import com.common.app.R;
import com.common.base.utils.transform.GlideRoundTransform;
import com.common.base.utils.ImgUrlUtils;
import com.common.app.widget.mybanner.loader.RoundImageLoader;

public class GlideImageRoundCompressionLoader extends RoundImageLoader {

    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {

        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.ic_error_banner_round)
                .error(R.drawable.ic_error_banner_round)
                .skipMemoryCache(true)
                .disallowHardwareConfig()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .transform(new GlideRoundTransform(10));

        Glide.with(context)
//                .load(ImgUrlUtils.getOne2One(ImgUrlUtils.TYPE_HW,path.toString(), 1068, 600))//
                .load(ImgUrlUtils.getWidthAutoScale(
                        ImgUrlUtils.TYPE_AL,
                        path.toString(),
                        1440,"webp"
                ))
                .apply(options)
                .transition(DrawableTransitionOptions.with(new DrawableCrossFadeFactory.Builder(GLIDE_FADE_IN_TIME).setCrossFadeEnabled(true).build()))//渐入动画效果
                .into(imageView);

    }


}
